//
//  ANProductDetailTableViewCell.m
//  Ants
//
//  Created by ZHM on 16/3/29.
//  Copyright © 2016年 ZHM. All rights reserved.
//

#import "ANProductDetailTableViewCell.h"
#import "ANProductDetailCellFrame.h"

@interface ANProductDetailTableViewCell ()

@property (nonatomic, strong) UILabel *nameLable;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *originPriceLabel;
@property (nonatomic, strong) UILabel *serversLabel;

@end

@implementation ANProductDetailTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
static NSString *ID = @"CELL";
+ (instancetype)cellWithTableView:(UITableView *)tabalView {
    ANProductDetailTableViewCell *cell = [[ANProductDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    //CeLL不显示选中状态
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)setProdcutDetailCellFrame:(ANProductDetailCellFrame *)prodcutDetailCellFrame {
    _prodcutDetailCellFrame = prodcutDetailCellFrame;

    _nameLable.text = prodcutDetailCellFrame.product.title;
    _detailLabel.text = prodcutDetailCellFrame.product.intro;
    _priceLabel.text = prodcutDetailCellFrame.priceLabelText;
    
    _originPriceLabel.text = prodcutDetailCellFrame.originPriceLabelText;
    _serversLabel.text = prodcutDetailCellFrame.serversText;
    
    NSAttributedString *theAttributedString;
    theAttributedString = [[NSAttributedString alloc] initWithString:prodcutDetailCellFrame.originPriceLabelText attributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
    self.originPriceLabel.attributedText = theAttributedString;
    
    
    
    _nameLable.frame = prodcutDetailCellFrame.nameLabelFrame;
    _detailLabel.frame = prodcutDetailCellFrame.detailLabel;
    _priceLabel.frame = prodcutDetailCellFrame.priceLabel;
    _originPriceLabel.frame = prodcutDetailCellFrame.originPriceLabel;
    _serversLabel.frame = prodcutDetailCellFrame.serverLabel;
}
//注意:cell是用initWithStyle初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //添加所有子控件
        [self addUpAllChildView];
        //cell背景颜色
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)addUpAllChildView {
    
    UILabel *nameLable = [[UILabel alloc] init];
    [self addSubview:nameLable];
    nameLable.font = ANNameLabelSize;
    nameLable.numberOfLines = 0;
    _nameLable = nameLable;
    
    UILabel *detailLabel = [[UILabel alloc] init];
    detailLabel.font = ANDetailLabelSize;
    detailLabel.textColor = [UIColor grayColor];
    //换行
    detailLabel.numberOfLines = 0;
    [self addSubview:detailLabel];
    _detailLabel = detailLabel;
    
    UILabel *priceLabel = [[UILabel alloc] init];
    priceLabel.font = ANpriceLabelSize;
    priceLabel.textColor = [UIColor orangeColor];
    [self addSubview:priceLabel];
    _priceLabel = priceLabel;
    
    UILabel *originPriceLabel = [[UILabel alloc] init];
    originPriceLabel.font = ANoriginPriceLabelSize;
    originPriceLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:originPriceLabel];
    _originPriceLabel = originPriceLabel;
    
    UILabel *serversLabel = [[UILabel alloc] init];
    serversLabel.font = ANDetailLabelSize;
    serversLabel.numberOfLines = 0;
    [self addSubview:serversLabel];
    _serversLabel = serversLabel;

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
